package tasks;

import java.util.ArrayList;

import javax.swing.SwingWorker;

import core.Torrent;
import core.TorrentManager;

public class UpdateProgressBar extends SwingWorker {
	private Torrent torrent;

	public UpdateProgressBar(Torrent torrent) {
		this.torrent = torrent;
	}

	@Override
	protected Object doInBackground() throws Exception {
		int avancement = -1;

		try {
			do {	
				avancement = this.torrent.getAvancement();	
				setProgress(avancement);			

				Thread.sleep(500);
			} while(avancement < 99 && TorrentManager.getInstance().getTorrents().contains(this.torrent));
		} catch(Exception e) {
			System.out.println("UpdateProgressBar|Exception: "+e);
		}		
		
		setProgress(100);
		
		return null;
	}

}
